package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.ExportDao;
import cn.itcast.dao.cargo.PackingDao;
import cn.itcast.domain.cargo.Export;
import cn.itcast.domain.cargo.Incasement;
import cn.itcast.domain.cargo.IncasementProxy;
import cn.itcast.service.cargo.PackingService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class PackingServiceImpl implements PackingService {

    @Autowired
    private PackingDao packingDao;

    @Autowired
    private ExportDao exportDao;

    @Override
    public PageInfo<Incasement> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Incasement> list=packingDao.findAll();
        PageInfo<Incasement> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void deleteById(String packingListId) {
        packingDao.deleteById(packingListId);
    }

    @Override
    public Incasement findIncasementById(String packingListId) {
        return packingDao.findIncasementById(packingListId);
    }

    @Override
    public void insertSelective(IncasementProxy incasementProxy) {
        packingDao.insertSelective(incasementProxy);
    }

    @Override
    public void updateIncasement(Incasement incasement) {
        packingDao.updateIncasement(incasement);
    }

    @Override
    public void save(Incasement incasement) {
        incasement.setPackingListId(UUID.randomUUID().toString());
        //补全装箱单信息
        incasement.setState(0);
        packingDao.insertSelective1(incasement);
    }

    @Override
    public boolean findState(String packingListId) {
        int state=packingDao.findState(packingListId);
        if(state==0){
            return true;
        }else{
            return false;
        }
    }



   /* @Override
    public Export findExportByPackingListId(String packingListId) {
        Incasement incasement=packingDao.findIncasementById(packingListId);

        String[] exportId = incasement.getExportIds().split(",");
        Export export=exportDao.findExportById(exportId[0]);

        return export;
    }*/
}
